package com.dynamixsoftware.printershare.snmp;

import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import java.util.StringTokenizer;

public class SNMPObjectIdentifier
  extends SNMPObject
{
  private long[] digits;
  protected byte tag = 6;
  
  public SNMPObjectIdentifier()
  {
    this.digits = new long[0];
  }
  
  public SNMPObjectIdentifier(String paramString)
    throws SNMPBadValueException
  {
    convertDigitString(paramString);
  }
  
  protected SNMPObjectIdentifier(byte[] paramArrayOfByte)
    throws SNMPBadValueException
  {
    extractFromBEREncoding(paramArrayOfByte);
  }
  
  public SNMPObjectIdentifier(int[] paramArrayOfInt)
    throws SNMPBadValueException
  {
    long[] arrayOfLong = new long[paramArrayOfInt.length];
    for (int i = 0; i < paramArrayOfInt.length; i++)
    {
      if (paramArrayOfInt[i] < 0) {
        throw new SNMPBadValueException("Negative value supplied for SNMPObjectIdentifier.");
      }
      arrayOfLong[i] = paramArrayOfInt[i];
    }
    this.digits = arrayOfLong;
  }
  
  public SNMPObjectIdentifier(long[] paramArrayOfLong)
    throws SNMPBadValueException
  {
    for (int i = 0; i < paramArrayOfLong.length; i++) {
      if (paramArrayOfLong[i] < 0L) {
        throw new SNMPBadValueException("Negative value supplied for SNMPObjectIdentifier.");
      }
    }
    this.digits = paramArrayOfLong;
  }
  
  private void convertDigitString(String paramString)
    throws SNMPBadValueException
  {
    int i;
    try
    {
      StringTokenizer localStringTokenizer1 = new StringTokenizer(paramString, " .");
      i = 0;
      while (localStringTokenizer1.hasMoreTokens())
      {
        i++;
        localStringTokenizer1.nextToken();
      }
      arrayOfLong = new long[i];
    }
    catch (NumberFormatException localNumberFormatException)
    {
      throw new SNMPBadValueException(" Object Identifier: bad string supplied for object identifier value ");
    }
    long[] arrayOfLong;
    StringTokenizer localStringTokenizer2 = new StringTokenizer(paramString, " .");
    for (int j = 0;; j++) {
      if (j < i)
      {
        arrayOfLong[j] = Long.parseLong(localStringTokenizer2.nextToken());
        if (arrayOfLong[j] < 0L) {
          throw new SNMPBadValueException(" Object Identifier: bad string supplied to set value ");
        }
      }
      else
      {
        this.digits = arrayOfLong;
        return;
      }
    }
  }
  
  private byte[] encodeArray()
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    int i = this.digits.length;
    if (i >= 2) {
      localByteArrayOutputStream.write((byte)(int)(40L * this.digits[0] + this.digits[1]));
    }
    for (;;)
    {
      for (int j = 2; j < i; j++)
      {
        byte[] arrayOfByte = encodeValue(this.digits[j]);
        localByteArrayOutputStream.write(arrayOfByte, 0, arrayOfByte.length);
      }
      if (i == 1) {
        localByteArrayOutputStream.write((byte)(int)(40L * this.digits[0]));
      }
    }
    return localByteArrayOutputStream.toByteArray();
  }
  
  private byte[] encodeValue(long paramLong)
  {
    int i = 0;
    long l1 = paramLong;
    do
    {
      i++;
      l1 = Math.floor(l1 / 128L);
    } while (l1 > 0L);
    byte[] arrayOfByte = new byte[i];
    arrayOfByte[(i - 1)] = ((byte)(int)(paramLong % 128L));
    long l2 = Math.floor(paramLong / 128L);
    for (int j = i - 2; j >= 0; j--)
    {
      arrayOfByte[j] = ((byte)(int)(128L + l2 % 128L));
      l2 = Math.floor(l2 / 128L);
    }
    return arrayOfByte;
  }
  
  private void extractFromBEREncoding(byte[] paramArrayOfByte)
    throws SNMPBadValueException
  {
    int i = 0;
    for (int j = 0; j < paramArrayOfByte.length; j++) {
      if ((0x80 & paramArrayOfByte[j]) == 0) {
        i++;
      }
    }
    if (i > 0)
    {
      this.digits = new long[i + 1];
      int k = -1;
      long l1 = 0L;
      do
      {
        k++;
        l1 = 128L * l1 + (0x7F & paramArrayOfByte[k]);
      } while ((0x80 & paramArrayOfByte[k]) > 0);
      this.digits[0] = (Math.floor(l1 / 40L));
      this.digits[1] = (l1 % 40L);
      for (int m = 2; m < i + 1; m++)
      {
        long l2 = 0L;
        do
        {
          k++;
          l2 = 128L * l2 + (0x7F & paramArrayOfByte[k]);
        } while ((0x80 & paramArrayOfByte[k]) > 0);
        this.digits[m] = l2;
        if (this.digits[m] == 0L) {
          this.digits[m] = 0L;
        }
      }
    }
    this.digits = new long[0];
  }
  
  public boolean equals(Object paramObject)
  {
    if (paramObject == null) {
      return false;
    }
    if (!getClass().equals(paramObject.getClass())) {
      return false;
    }
    SNMPObjectIdentifier localSNMPObjectIdentifier = (SNMPObjectIdentifier)paramObject;
    return Arrays.equals((long[])getValue(), (long[])localSNMPObjectIdentifier.getValue());
  }
  
  protected byte[] getBEREncoding()
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    byte[] arrayOfByte1 = encodeArray();
    byte[] arrayOfByte2 = SNMPBERCodec.encodeLength(arrayOfByte1.length);
    localByteArrayOutputStream.write(6);
    localByteArrayOutputStream.write(arrayOfByte2, 0, arrayOfByte2.length);
    localByteArrayOutputStream.write(arrayOfByte1, 0, arrayOfByte1.length);
    return localByteArrayOutputStream.toByteArray();
  }
  
  public Object getValue()
  {
    return this.digits;
  }
  
  public int hashCode()
  {
    int i = 0;
    for (int j = 0; j < this.digits.length; j++)
    {
      int n = i + (int)(this.digits[j] ^ this.digits[j] >> 32);
      int i1 = n + (n << 10);
      i = i1 ^ i1 >> 6;
    }
    int k = i + (i << 3);
    int m = k ^ k >> 11;
    return m + (m << 15);
  }
  
  public void setValue(Object paramObject)
    throws SNMPBadValueException
  {
    if ((paramObject instanceof long[]))
    {
      for (int j = 0; j < ((long[])paramObject).length; j++) {
        if (((long[])(long[])paramObject)[j] < 0L) {
          throw new SNMPBadValueException("Negative value supplied for SNMPObjectIdentifier.");
        }
      }
      this.digits = ((long[])paramObject);
      return;
    }
    if ((paramObject instanceof int[]))
    {
      long[] arrayOfLong = new long[((int[])paramObject).length];
      for (int i = 0; i < ((int[])paramObject).length; i++)
      {
        if (((int[])(int[])paramObject)[i] < 0) {
          throw new SNMPBadValueException("Negative value supplied for SNMPObjectIdentifier.");
        }
        arrayOfLong[i] = ((int[])(int[])paramObject)[i];
      }
      this.digits = arrayOfLong;
      return;
    }
    if ((paramObject instanceof String))
    {
      convertDigitString((String)paramObject);
      return;
    }
    throw new SNMPBadValueException(" Object Identifier: bad object supplied to set value ");
  }
  
  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    if (this.digits.length > 0)
    {
      localStringBuffer.append(this.digits[0]);
      for (int i = 1; i < this.digits.length; i++)
      {
        localStringBuffer.append(".");
        localStringBuffer.append(this.digits[i]);
      }
    }
    return localStringBuffer.toString();
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.snmp.SNMPObjectIdentifier
 * JD-Core Version:    0.7.0.1
 */